#include <iostream>
#include <algorithm>
#include <cstdlib>
int main(int argc, char** argv){
	int i,k;
	for(i=0;argv[1][i] != '\0';i++);
	for(k=0; 1 << k <= i +k +1;k++);
	std::cout <<"i=" << i << " k="<< k << std::endl;
	int len = k + i;
	int j = 0,t = 0,p = 0;
	int* hammingBytes = (int*)malloc(sizeof(int) * len);
	std::fill(hammingBytes,hammingBytes + len,0);
	for(j=2,i=0,k=2; j<len; j++){
		if(j == (1 << k) -1){
			k++;
			continue;
		}
		hammingBytes[j] = argv[1][i] - '0';
		// 偶检验运算
		t = k - 1;
		p = j + 1;
		i++;
		while(t >= 0){
			if(p >> t == 1){
				int index = (1 << t) -1;
				std::cout << "D" << index + 1 << " ^="<< " P" << j+1 << std::endl;
				hammingBytes[index] = hammingBytes[index] ^ hammingBytes[j];
			}
			p = p - (1 << t);
			while(1 << --t > p);
		}
	}
	for(i =0;i< len;i++){
		std::cout <<  hammingBytes[i];
	}
	std::cout << std::endl;
}
